<%@page import="org.springframework.ui.Model"%>
<%@page import="com.sofly.entity.Bom"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>bom管理</title>
</head>
<body>
	<!-- jQuery 主文件 -->
	<script type="text/javascript" src="../js/jquery.min.js" ></script>
	<!-- easyui 主文件 -->
	<script type="text/javascript" src="../js/jquery.easyui.min.js" ></script>
	<!-- 国际化文件 -->
	<script type="text/javascript" src="../js/locale/easyui-lang-zh_CN.js" ></script>
	<!-- easyui 主样式文件 -->
	<link rel="stylesheet" href="../js/themes/black/easyui.css" />
	<link rel="stylesheet" href="../js/themes/icon.css" />	
	<script type="text/javascript">
	   $(function(){
		$("#tb").datagrid({
	   	url:"boms",
	   	method:"get",
	   	queryParams:{flag:"i"},
		columns:[[  
            {field:'Id',title:'全选',width:100,checkbox:true},      
	        {field:'stocknumber',title:'物料编号',width:100,align:'center'},    
	        {field:'stockstandard',title:'物料规格',width:100,align:'center'},    
	        {field:'stockname',title:'物料名称',width:100,align:'center'}, 
	        {field:'sum',title:'需求量',width:100,align:'center'},
			{field:'unit',title:'计量单位',width:100,align:'center'},
			{field:'purpose',title:'组件',width:100,align:'center'}, 
			{field:'parentcomponent',title:'信息',width:100,align:'center'}, 
			{field:'purchasedate',title:'操作栏',width:110,align:'center'},
	    ]],
	    fit:true,
		toolbar:[{
			iconCls: 'icon-edit',
			text:"编辑",
			handler:function(){
				edit();
			}
		},{
			iconCls: 'icon-add',
			text:"添加",
			handler:function(){
				add();
			}
		},{
			iconCls: 'icon-search',
			text:"查询",
			handler:function(){
				select();
			}
		},{
			iconCls: 'icon-print',
			text:"打印",
			handler:function(){
				print();
			}
		}
		],
		onLoadSuccess:function(){//数据加载完毕之后触发事件..,想让数据端某列作为js按钮,就需要加载完数据后,给该列赋予easyui的类属性
			$("#btn_1").linkbutton({    
			    iconCls: 'icon-add'   
			});  
		},
		loadMsg:"数据加载中...，请等待!",
		singleSelect:true,
		fitColumns:true,
		pagination:true,
		rownumbers:true
	})
	
function print(){
	var row = $('#tb').datagrid('getSelected');	
	if (row&&row.remark=="未下单"){
		if(confirm("确定下单？")){
		location="pdf?purchaseId="+row.purchaseId;
		$('#tb').datagrid('reload');
		}
	}else{
		alert("该产品已下单");
	}
	
}
function add(){
	$('#win').dialog('open').dialog('setTitle','添加');
	$('#fm').form('clear');
	url = 'addPurchaseList'
}
function edit(){
	var row = $('#tb').datagrid('getSelected');
	if (row){
		$('#win').dialog('open').dialog('setTitle','编辑');
		$('#fm').form('load',row);	
		url = 'editPurchaseList';
	}
}
function saveUser(){
	$('#fm').form('submit',{
		url:url,
		onSubmit: function(){
			return $(this).form('validate');
		},
		success: function(result){	 
			if (result=='1'){
				$.messager.show({
					title: 'Error',
					msg: "操作失败" 
				});
			} else {
				$('#win').dialog('close');		// close the dialog
				$('#tb').datagrid('reload');	// reload the user data
			}
		}
	});
}
function select(){
	$('#won').dialog('open').dialog('setTitle','查询订单');
}
function Search(){
	var  v = $("#ser").val();
	 $.get("SearchPurchaseList",
		   {purchaseId:v},
		   function(data1){
			$('#won').dialog('close'); 
			$('#butt').attr('disabled',"true");
			var data = eval("("+data1+")");
			$('#win').dialog('open').dialog('setTitle','订单');
			$('#fm').form('load',data);
		});
}
	   })
	</script>
	<style type="text/css">
		#fm{
			margin:0;
			padding:10px 30px;
		}
		.ftitle{
			font-size:14px;
			font-weight:bold;
			color:#666;
			padding:5px 0;
			margin-bottom:10px;
			border-bottom:1px solid #ccc;
		}
		.fitem{
			margin-bottom:5px;
		}
		.fitem label{
			display:inline-block;
			width:80px;
		}
	</style>
	</head>
	<body>
		<table id="tb" title="查看bom"></table>
	 	<div id="win" class="easyui-dialog" style="width:400px;height:400px;padding:10px 20px"
			closed="true" buttons="#dlg-buttons">
		<div class="ftitle">PurchaseList Information</div>
		<form id="fm" method="post" novalidate>
			<div class="fitem">
				<label>purchaseId:</label>
				<input name="purchaseId" class="easyui-validatebox" required="true">
			</div>
		</form>
	</div>
	<div id="won" class="easyui-dialog" style="width:400px;height:200px;padding:10px 20px"
			closed="true" buttons="#dlg-button">
			<div class="ftitle">PurchaseList Information</div>
			<form id="fm" method="post" novalidate>
			<div class="fitem">
				<label>stocknumber:</label>
				<input id ="ser" name="purchaseId" class="easyui-validatebox" required="true">
			</div>
			<div class="fitem">
				<label>stockstandard:</label>
				<input id ="ser" name="purchaseId" class="easyui-validatebox" required="true">
			</div>
			<div class="fitem">
				<label>stockname:</label>
				<input id ="ser" name="purchaseId" class="easyui-validatebox" required="true">
			</div>
			<div class="fitem">
				<label>sum:</label>
				<input id ="ser" name="purchaseId" class="easyui-validatebox" required="true">
			</div>
			<div class="fitem">
				<label>unit:</label>
				<input id ="ser" name="purchaseId" class="easyui-validatebox" required="true">
			</div>
			<div class="fitem">
				<label>purpose:</label>
				<input id ="ser" name="purchaseId" class="easyui-validatebox" required="true">
			</div>
			<div class="fitem">
				<label>productPrices:</label>
				<input id ="ser" name="purchaseId" class="easyui-validatebox" required="true">
			</div>
			<div class="fitem">
				<label>parentcomponent:</label>
				<input id ="ser" name="purchaseId" class="easyui-validatebox" required="true">
			</div>
			<div class="fitem">
				<label>purchasedate:</label>
				<input id ="ser" name="purchaseId" class="easyui-validatebox" required="true">
			</div>
			<div class="fitem">
				<label><a href="###">查看</a></label>
				<input id ="ser" name="purchaseId" class="easyui-validatebox" required="true">
			</div>
			</form>
	</div>
	<div id="dlg-button">
		<a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="Search()">Search</a>
		<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#won').dialog('close')">Cancel</a>
	</div>
	<div id="dlg-buttons">
		<a href="#" id="butt" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveUser()" >Save</a>
		<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#win').dialog('close')">Cancel</a>
	</div> 
	</body>
</html>